// 用户相关请求模块
import qs from 'qs'
import request from '@/utils/api/request'
// // 用户登录
// export function create (data) {
//   return request({
//     method: 'POST',
//     url: '/group/detele'
//   })
// }
// 获取全部小组列表
export const getGroup = () => {
  return request({
    method: 'GET',
    url: '/group/getAll',
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded'
    }
  })
}
// 创建小组请求
export const addGroup = (params, data) => {
  return request({
    method: 'POST',
    url: '/group/create',
    params,
    data
  })
}
// 删除小组请求
export const deleteGroup = groupId => {
  return request({
    method: 'GET',
    url: `/group/delete/${groupId}`
  })
}

// 创建邀请码
export function createGroupCode (data) {
  return request({
    method: 'POST',
    url: `/group/generateCode`,
    data: qs.stringify(data),
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded',
    }
  })
}
// 获取小组详情页信息（包括组员，总数等）
export const getList = listId => {
  return request({
    method: 'GET',
    url: `/group/details?gid=${listId}`
  })
}
// 获取小组简介
export const getIntro = listId => {
  return request({
    method: 'GET',
    url: `/group/get/${listId}`
  })
}
// 更新小组详情页信息
export const updateGroup = (gid, data) => {
  return request({
    method: 'POST',
    url: `/group/update/${gid}`,
    data,
    headers: {
      'Content-Type': 'application/json; charset=utf-8',
    }
  })
}
// 删除小组成员
export function deleteGroupMembers (data) {
  return request({
    method: 'POST',
    url: `/group/deleteMember`,
    data: qs.stringify(data),
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded',
    }
  })
}

// 加入小组
export function joinGroup (data) {
  return request({
    method: 'POST',
    url: `/group/join`,
    data: qs.stringify(data),
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded',
    }
  })
}
// 获取自己创建的组
export function getCreateGroup () {
  return request({
    method: 'get',
    url: `/group/getCreate`,
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded',
    }
  })
}
// 获取小组的文章
export const allDocs = listId => {
  return request({
    method: 'GET',
    url: `/GroupLib/groupDocment/all?gid=${listId}`,
  })
}
// 根据id获取小组文章的详情页
export const getArchive = listId => {
  return request({
    method: 'GET',
    url: `/GroupLib/groupDocument/archive?docid=${listId}`
  })
}
// 删除文档
export function deleDoc (data) {
  return request({
    method: 'DELETE',
    url: `/GroupLib/groupDocument?docid=` + data,
    data: qs.stringify(data),
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded',
    }
  })
}

// 查询某一用户在该小组内的文档
export const getPerson = (listId, user) => {
  return request({
    method: 'GET',
    url: `/GroupLib/groupDocment/user?gid=${listId}&username=${user}`
  })
}
// 模糊查询
export const search = (gid, name) => {
  return request({
    method: 'GET',
    url: `/group/fuzzySelect?gid=${gid}&name=${name}`
  })
}
